package com.atguigu.eduservice.controller.index;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
//@CrossOrigin
@RestController
@RequestMapping("/eduservice/frontteacher")
public class TeacherController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;


    @ApiOperation(value = "前端页面教师分页查询")
    @PostMapping("pageTeacherList/{current}/{limit}")
    public R pageListTeacher(@PathVariable Long current, @PathVariable Long limit){

        Page<EduTeacher> pageParam = new Page<>(current, limit);
        Page<EduTeacher> teacherPage =  teacherService.getTeacherPageList(pageParam);

//        System.out.println("teacherPage: " + teacherPage);

        return R.ok().data(teacherPage);

    }

    //2 讲师详情的功能
    @ApiOperation(value = "讲师详情功能")
    @GetMapping("teacherInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){

        EduTeacher teacher = teacherService.getById(teacherId);
        //根据讲师idc查询所讲课程

        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();
        courseWrapper.eq("teacher_id", teacherId);

        List<EduCourse> eduCourseList = courseService.list(courseWrapper);
        HashMap<String, Object> map = new HashMap<>();
        map.put("teacher", teacher);
        map.put("courseList", eduCourseList);

        return R.ok().data(map);


    }


}
